<template>
  <div class="account-table-wrap">
    <el-table
      :data="tableData"
      style="width: 100%"
      :border="true"
      :fit="true"
      :stripe="true"
      size="mini"
      align="center">
      <el-table-column
        prop="id"
        label="id"
        min-width="70"
        align="center">
      </el-table-column>

      <el-table-column
        prop="number"
        label="配料编号"
        min-width="120"
        align="center">
      </el-table-column>

      <el-table-column
        prop="material_name"
        label="名称"
        min-width="130"
        align="center">
      </el-table-column>

      <el-table-column
        prop="formats"
        label="规格/型号"
        min-width="320"
        align="center">
        <template slot-scope="scope">
          <div class="check-list" @click="add(scope.$index)" v-text="(scope.row.formats).join('，')"></div>
        </template>
      </el-table-column>

      <el-table-column
        prop="unit"
        label="单位"
        min-width="50"
        align="center">
      </el-table-column>

      <el-table-column label="操作"
      min-width="140"
      align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            plain
            type="primary"
            @click="tableEdit(scope.row)">编辑</el-button>
          <el-button
            size="mini"
            plain
            type="danger"
            @click="tableDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- <deleteConfirm v-if="showMask1" @closeDelete="closeDelete" @deleteConfirm="deleteConfirm"></deleteConfirm> -->
    <el-dialog title="删除" v-if="showMask2" center width="400px" :visible="true" @close="closeDelete">
      <div :style="{'textAlign':'center'}">此项配料已经关联到商品：{{hasGoods}}</div>
      <div :style="{'textAlign':'center','color':'red'}">删除后,商品配料清单将对应清空，慎重操作!</div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="closeDelete">取 消</el-button>
          <el-button type="primary" @click="deleteConfirm">确 定</el-button>
        </span>
    </el-dialog>

    <el-dialog title="删除" v-if="showMask1" center width="400px" :visible="true" @close="closeDelete">
      <div :style="{'textAlign':'center'}">确定删除此项信息吗?</div>
      <div :style="{'textAlign':'center','color':'red'}">删除后,库存信息将对应清空，慎重操作!</div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="closeDelete">取 消</el-button>
          <el-button type="primary" @click="deleteConfirm">确 定</el-button>
        </span>
    </el-dialog>

  </div>
</template>
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import { Prop, Emit } from 'vue-property-decorator';
import deleteConfirm from '@/components/deleteConfirm.vue';
import ajaxResquest from '@/api/apiRequest';
@Component({
  components: {
    deleteConfirm
  }
})
export default class AccountListTable extends Vue {
  @Prop({
    type: Array
  })
  tableData!: any[];
  showMask1: boolean = false;
  showMask2: boolean = false;
  deleteId!: number;
  deleteRes!: ajaxResquest;

  hasGoods: string = '';
  tableEdit(row: any) {
    this.$to('accessListCreate', { edit: true, id: row.id });
  }
  mounted() {
    this.deleteRes = new ajaxResquest('/materials/delMaterials');
  }
  tableDelete(row: any) {
    console.log(row.hasMaterialsGoodsInfos);
    if (row.hasMaterialsGoodsInfos) {
      this.showMask2 = true;
      this.hasGoods=row.goodsName.join('，')
    } else {
      this.showMask1 = true;
    }
    this.deleteId = row.id;
  }
  closeDelete(row: object) {
    this.showMask1 = false;
    this.showMask2 = false;
  }
  deleteConfirm() {
    console.log('done');
    this.deleteRes.getFunction({ materialsId: this.deleteId }).then((res:any) => {
      if (res.data.code === 1) {
        this.getData();
        this.showMask1 = false;
        this.showMask2 = false;
      }
    });
  }
  @Emit('getData')
  getData() {}
}
</script>
<style>
.account-table-wrap {
}
</style>
